package com.helloandroid.receivers

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.hardware.usb.UsbManager
import com.helloandroid.services.ServerService
import com.helloandroid.tools.MyLog

class BootReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {
        when(intent.action){

            // 开机启动
            Intent.ACTION_BOOT_COMPLETED,

            // 挂载 sdcard
            Intent.ACTION_MEDIA_MOUNTED,
            Intent.ACTION_MEDIA_REMOVED,
            UsbManager.ACTION_USB_DEVICE_ATTACHED,
            UsbManager.ACTION_USB_DEVICE_DETACHED,

            //  VolumeInfo.java 中
            "android.os.storage.action.VOLUME_STATE_CHANGED",

            //
            "android.net.conn.CONNECTIVITY_CHANGE",
            "android.intent.action.PACKAGE_REPLACED",
            Intent.ACTION_TIME_TICK,
            "android.intent.action.USER_PRESENT" -> {
                MyLog.info("收到了通知.  action:${intent.action}")
                val intent = Intent(context,ServerService::class.java)
                intent.putExtra("deamon",1)
                context.startService(intent)
            }
        }
    }
}